package com.work.csms.service;

import com.work.csms.dao.Station;
import com.work.csms.mapper.StationMapper;
import com.work.csms.pojo.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StationService {

    @Autowired(required = false)
    private StationMapper stationMapper;

    public Map<String, Object> page(Station station, PageParam pageParam) throws Exception {
        Map<String, Object> result = new HashMap<>();
        Integer count = stationMapper.count(station.getCode());
        List<Station> page = stationMapper.page(station.getCode(), (pageParam.getPageNo() - 1) * pageParam.getPageSize(), pageParam.getPageSize());
        result.put("count", count);
        result.put("pageSize", pageParam.getPageSize());
        result.put("pageNo", pageParam.getPageNo());
        result.put("data", page);
        return result;
    }

    public List<Station> list(Station station) throws Exception {
        return stationMapper.list(station);
    }

    public Station getStationById(Integer id) throws Exception {
        return stationMapper.getStationById(id);
    }

    public void save(Station station) throws Exception {
        stationMapper.save(station);
    }

    public void update(Station station) throws Exception {
        stationMapper.update(station);
    }

    public void deleted(Integer id) throws Exception {
        stationMapper.deleted(id);
    }

}
